﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

using MainDataSetTableAdapters;
using System.Data;
namespace YJXM.GYMK
{
    public class TempRoleProvider:RoleProvider
    {
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            string rolesList = "系统管理员,买家,卖家";
            return rolesList.Split(',');
        }

        public override string[] GetRolesForUser(string username)
        {
            username = username.ToLower();
            string[] roles = new string[1];
            TA_UserTableAdapter ta = new TA_UserTableAdapter();
            DataTable dt=ta.GetUserRoleByUserIDForLogin(username);
            roles[0] = dt.Rows[0]["role"].ToString();    
            //if (username.Equals("buyer")) roles[0] = "买家";
            //else if (username.Equals("seller")) roles[0] = "卖家";            
            //else if (username.Equals("admin")) roles[0] = "系统管理员";          
            return roles;
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            string[] roles = this.GetRolesForUser(username);
            if (roles[0].Equals(roleName)) return true;
            return false;
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            string rolesList = "买家,卖家,系统管理员";
            if (rolesList.IndexOf("," + roleName + ",") >= 0) return true;
            return false;
        }
    }
}